package com.bezdelnick.forum.web.page;

import com.bezdelnick.forum.service.ForumService;
import com.bezdelnick.forum.web.component.LoginForm;
import com.bezdelnick.forum.web.page.template.UserMainMenuTemplate;
import com.bezdelnick.forum.web.panel.ModeratorMainMenuPanel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 16.08.12
 * Time: 23:53
 * To change this template use File | Settings | File Templates.
 */
public class LoginPage extends UserMainMenuTemplate {
    private static final Logger LOGGER = LoggerFactory.getLogger(LoginPage.class);

    private ForumService.MODE mode;
    private String expectedAuth = "user";

    private LoginForm loginForm;

    public LoginPage() {
        this(new PageParameters());
    }

    public LoginPage(PageParameters pageParameters) {
        this.getPageParameters().mergeWith(pageParameters);

        if (! pageParameters.get("userRequest").isNull()) {
            String value = pageParameters.get("userRequest").toString();
            expectedAuth = pageParameters.get("exp").toString();

            if (value.equals("ok")) {
                loginForm = new LoginForm("form", true);
            } else {
                loginForm = new LoginForm("form", false);
            }
        } else
            loginForm = new LoginForm("form", false);

        if (! expectedAuth.equals("user")) {
            remove("mainPanel");
            add(new ModeratorMainMenuPanel("mainPanel"));
        }
        add(loginForm);
    }
}
